package com.yugao.fintech.antelope.system.handler.config;

import com.yugao.fintech.antelope.base.config.GlobalProperties;
import com.yugao.fintech.antelope.infra.InfraApi;
import com.yugao.fintech.antelope.base.model.constants.ServiceCodeCons;
import com.yugao.fintech.antelope.base.model.enums.ConfigKeyEnum;
import com.yugao.fintech.antelope.base.model.module.config.param.BaseConfigParam;
import com.yugao.fintech.antelope.base.model.module.config.param.WxCpParam;
import com.yugao.fintech.antelope.base.model.module.tenant.TenantContextHolder;
import com.yugao.fintech.antelope.system.model.entity.SysConfig;
import com.yugao.fintech.framework.assistant.utils.UrlUtils;
import org.springframework.stereotype.Component;

import java.util.Optional;


@Component
public class WxCpConfigHandler extends ConfigHandler {
    @Autowired
    private InfraApi infraApi;
    @Autowired
    private GlobalProperties properties;

    @Override
    public void doneWriteOps(SysConfig newConfig, BaseConfigParam<?> param) {
        WxCpParam wxCpParam = (WxCpParam) param;

    }

    @Override
    protected BaseConfigParam<?> doneReadOps(BaseConfigParam<?> param) {
        WxCpParam wxCpParam = (WxCpParam) param;
        wxCpParam = Optional.ofNullable(wxCpParam).orElse(new WxCpParam());
        Long tenantId = TenantContextHolder.get().getTenantId();
        wxCpParam.setMsgPushUrl(UrlUtils.removeRepeatSlashOfUrl(properties.getServerAddr() + "/" + ServiceCodeCons.INFRA_SERVICE + "/open/wxCp/" + tenantId));
        return wxCpParam;
    }

    @Override
    public ConfigKeyEnum configKey() {
        return ConfigKeyEnum.WX_CP;
    }
}
